package com.john.test.http.proxy.parser;

import com.john.test.http.proxy.data.ProxyItem;
import com.john.http.core.parser.config.HtmlParseConfig;
import com.john.http.core.convert.ChinaTimeUnitConverter;
import com.john.http.core.convert.DateValueConverter;
import com.john.http.core.convert.IntegerValueConverter;
import com.john.http.core.convert.RegexpDoubleValueConverter;
import com.john.http.core.util.DateUtil;

/**
 * 〈一句话功能简述〉<br/>
 * 〈功能详细描述〉
 *
 * @author jiangguangtao on 2016/4/28.

 */
public class ProxyGetterConfigUtil {

    /**
     * http://www.xicidaili.com/nn/ 此网站对应的解析配置
     *
     * @return
     */
    public static HtmlParseConfig getXidailiConfig() {
        return HtmlParseConfig.build()
                .headRows(1)
                .containerSelector("#ip_list")
                .rowSelector("tr")
                .fieldMapping(1, "ip")
                .fieldMapping(2, "port", new IntegerValueConverter())
                .fieldMapping(3, "location")
                .fieldMapping(5, "proxyType")
                .fieldMapping(6, "speed", new RegexpDoubleValueConverter(ProxyItem.DEFAULT_SPEED), "div", "title")
                .fieldMapping(7, "delay", new RegexpDoubleValueConverter(ProxyItem.DEFAULT_DELAY), "div", "title")
                .fieldMapping(8, "timeToLive", new ChinaTimeUnitConverter())
                .fieldMapping(9, "lastValidTime", new DateValueConverter(DateUtil.yyMMddHHmm));
    }
}
